* PARAMETERS FOR BLACKS AND HISPANICS

***************** MARRIAGE RATES *****************

* INITIAL DISTRIBUTION OF MARITAL TYPES BY EDUC
* for Table 120
qui {
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.
keep if RACE_sum==2 | RACE_sum==3
keep if AGE1==25 | AGE1==26
drop if H1==.
keep if educ_group==1

table RACE_sum H1 [aw=Sample_Weight] , stat(mean MAR1)
collapse (mean) MAR1 [aw=Sample_Weight], by(RACE_sum H1)
sort RACE_sum H1

preserve
keep if RACE_sum==2
drop RACE_sum
sort  H1
drop  H1
outsheet using "${data_model}\Blacks\Marriage0.txt", nolabel nonames replace	
restore 

keep if RACE_sum==3
drop RACE_sum
sort  H1
drop  H1
outsheet using "${data_model}\Hispanics\Marriage0.txt", nolabel nonames replace	
	


}



***** PROBABILITY OF GETTING MARRIED **********
qui {
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if AGE1<65 & AGE1>24
keep if educ_group==1
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.



drop if labor_force1==.

drop if year==2013 // we don't want to use data from 2014 which is the second year of the panel started in 2013
gen Mar_Indic1 = 0 if MAR1==0 & MAR3==0
replace  Mar_Indic1 = 1 if MAR1==0 & MAR3==1

table RACE_sum, stat(mean Mar_Indic1)

keep if RACE_sum==2 | RACE_sum==3
	
	label define incquint 1 "Income Quintile=1st" 2  "Income Quintile=2nd" 3  "Income Quintile=3rd" 4  "Income Quintile=4th" 5  "Income Quintile=5th"
label values inc_quintile_Y1  incquint
label var Mar_Indic1 "Single to Married"


* checking this out. 
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub     i.inc_quintile_Y1   i.labor_force1 i.H1 if RACE_sum==2
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub     i.inc_quintile_Y1   i.labor_force1 i.H1 if RACE_sum==3
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub       i.labor_force1  if RACE_sum==3


	eststo clear
replace labor_force1=1 if (labor_force1==2 | labor_force1==3)
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub   i.labor_force1  if RACE_sum==2  //  i.inc_quintile_Y1  
eststo
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub   i.labor_force1  if RACE_sum==3  //  i.inc_quintile_Y1  
eststo
	esttab using "${out_tables}/Reg1_races.tex", varwidth(25) nogaps   compress label nobaselevels indicate( "Cubic Age = *AGE1* *AGE1_sq* *AGE1_cub*" ) replace  ///
	 nonumbers noconstant eqlabel(none) star(* 0.1 ** 0.05 *** 0.01) ///
	se   b(3) 
	eststo clear

	fillin AGE1 labor_force1 RACE_sum
	replace AGE1_sq=AGE1^2 if _fillin==1
	replace AGE1_cub=AGE1^3 if _fillin==1
	
	* save predictions
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub       i.labor_force1 if RACE_sum==2 //  [pw=Sample_Weight]
	predict Y if RACE_sum==2, pr
logit Mar_Indic1 AGE1 AGE1_sq AGE1_cub       i.labor_force1 if RACE_sum==3
	predict Y3 if RACE_sum==3, pr
	replace Y=Y3 if RACE_sum==3
	drop Y3  

	
	
	collapse Y, by(AGE1 labor_force1 RACE_sum)
	* add all the "o" states
	 reshape wide Y, i(AGE1 RACE_sum ) j( labor_force1)
	 gen Y2=Y1
	 gen Y3=Y1
	 reshape long Y, i(AGE1 RACE_sum ) j( labor_force1)
	sort AGE1 labor_force1 RACE_sum
	drop if AGE1==24
	
preserve 
keep if 	RACE_sum==2 
sort AGE1 labor_force1 
drop AGE1 labor_force1 RACE_sum
outsheet using "${data_model}\Blacks\Marriage1.txt", nolabel nonames replace
restore
	
keep if 	RACE_sum==3 
sort AGE1 labor_force1 
drop AGE1 labor_force1 RACE_sum
outsheet using "${data_model}\Hispanics\Marriage1.txt", nolabel nonames replace

}


***** PROBABILITY OF GOING FROM MARRIED TO SINGLE 

qui {
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if AGE1<65 & AGE1>24
drop if labor_force1==.
drop if H1==.
keep if educ_group==1
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.
drop if year==2013 // we don't want to use data from 2014 which is the second year of the panel started in 2013

gen Mar_Indic2 = 0 if MAR1==1 & MAR3==1
replace  Mar_Indic2 = 1 if MAR1==1 & MAR3==0

keep if RACE_sum==2 | RACE_sum==3


label define incquint 1 "Income Quintile=1st" 2  "Income Quintile=2nd" 3  "Income Quintile=3rd" 4  "Income Quintile=4th" 5  "Income Quintile=5th"
label values inc_quintile_Y1  incquint
label var AGE1 "Age"

label var Mar_Indic2 "Married to Single"
	
replace labor_force1=1 if (labor_force1==2 | labor_force1==3)	
logit Mar_Indic2  AGE_YR1  AGE_SQ_YR1    if 	RACE_sum==2 
logit Mar_Indic2  AGE_YR1  AGE_SQ_YR1    if 	RACE_sum==3 
			
	fillin AGE1 RACE_sum
	
logit Mar_Indic2 AGE_YR1  AGE_SQ_YR1   if 	RACE_sum==2   // [pw=Sample_Weight]
	predict Y  if 	RACE_sum==2 , pr
logit Mar_Indic2 AGE_YR1  AGE_SQ_YR1   if 	RACE_sum==3   // [pw=Sample_Weight]
	predict Y2 if 	RACE_sum==3, pr
	replace Y= Y2 if RACE_sum==3
	collapse Y, by(AGE1 RACE_sum)
	sort RACE_sum AGE1 
drop if AGE1==24

table RACE_sum, stat(mean Y)

preserve
keep if RACE_sum==2 
sort AGE1
drop RACE_sum AGE1
outsheet using "${data_model}\Blacks\Marriage2.txt", nolabel nonames replace
restore

keep if RACE_sum==3 
sort AGE1
drop RACE_sum AGE1
outsheet using "${data_model}\Hispanics\Marriage2.txt", nolabel nonames replace
}




***** SPOUSE CHARACTERISTICS 

* PROBABILITY THE SPOUSE WORKS, CONDITIONAL ON MARRIED. 
* this depends on age, educ, and H. from ages 25-64.
qui {
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.
keep if AGE1<65 & AGE1>=25
drop if H1==.
keep if MAR1==1 & MAR2==1 // & MAR3==1

keep if educ_group==1

*EMPST
* 1 Employed at RD [.] Interview Date
* 2 Job to Return to at RD [.] Interview Date
* 3 Job During RD [.] Ref Period
* 4 Not Employed During RD [.]

* FT employment of men who are married, 25-64, by spouse's status

* spouse status
gen Spouse_status = 1 if MAR1==0 & MAR2==0
replace Spouse_status = 2 if MAR1==1 & MAR2==1 & spouse_LF_Y1==0
replace Spouse_status = 3 if MAR1==1 & MAR2==1 & spouse_LF_Y1==1
label define sp_stat 1 "Single" 2 "Married, Spouse N.E." 3 "Married, Spouse E."
label values Spouse_status sp_stat
label var Spouse_status "Marital and Spouse Status"
 
	fillin AGE1 H1 RACE_sum
	replace AGE1_sq=AGE1^2 if _fillin==1
	replace AGE1_cub=AGE1^3 if _fillin==1

	label var AGE1 "Age"
	label var AGE1_sq "Age sq"
	label var AGE1_cub "Age cub"
	
	
table RACE_sum, stat (mean spouse_LF_Y1)
	
	keep if RACE_sum==2 | RACE_sum==3
	

logit spouse_LF_Y1 AGE1 AGE1_sq AGE1_cub i.H1  if RACE_sum==2
predict Y2 if RACE_sum==2 , pr
logit spouse_LF_Y1 AGE1 AGE1_sq AGE1_cub i.H1  if RACE_sum==3 
predict Y3 if RACE_sum==3 , pr
egen Y=rowmax(Y2  Y3)
	collapse Y, by(AGE1 H1  RACE_sum)
	sort AGE1 RACE_sum H1 

* export data for Blacks
preserve 
keep if RACE_sum==2
drop RACE_sum
sort AGE1  H1 
drop AGE1  H1 
outsheet using "${data_model}\Blacks\Prob_spouse_work.txt", nolabel nonames replace	
restore 

* export data for Hispanics
keep if RACE_sum==3
drop RACE_sum
sort AGE1  H1 
drop AGE1  H1 
outsheet using "${data_model}\Hispanics\Prob_spouse_work.txt", nolabel nonames replace	

}


* SPOUSE'S AVERAGE INCOME
* for working ages, depends on age, educ, and if she works. 
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.
keep if AGE1<65 & AGE1>=25
drop if H1==.
keep if MAR1==1 & MAR2==1 // & MAR3==1

drop if spouse_LF_Y1==.
keep if educ_group==1

	drop if spouse_WAGE_YR1>113.89 & spouse_LF_Y1==0 // top 1% of whites
		tabstat spouse_WAGE_YR1 if spouse_LF_Y1==1, stat(min p25 p50 p90 p95  p99 max)

	
	
	table AGE1 RACE_sum if spouse_LF_Y1==1, stat(mean  spouse_WAGE_YR1) stat(p50  spouse_WAGE_YR1) stat(p50 spouse_income_YR1)
	
	table  RACE_sum if spouse_LF_Y1==1 & AGE1>40 & AGE1<50, stat(mean  spouse_WAGE_YR1) stat(p50  spouse_WAGE_YR1) 
	
	keep if RACE_sum==2  | RACE_sum==3

	fillin AGE1 H1 spouse_LF_Y1 RACE_sum
	replace AGE1_sq=AGE1^2 if _fillin==1
	replace AGE1_cub=AGE1^3 if _fillin==1
	
	label var AGE1 "Age"
	label var AGE1_sq "Age sq"
	label var AGE1_cub "Age cub"
	
	
	

reg  spouse_WAGE_YR1  AGE1 AGE1_sq AGE1_cub   [pw=Sample_Weight] if spouse_LF_Y1==0 & RACE_sum==2 
predict Y1 if spouse_LF_Y1==0 & RACE_sum==2 

reg  spouse_WAGE_YR1  AGE1 AGE1_sq AGE1_cub  [pw=Sample_Weight] if spouse_LF_Y1==0 & RACE_sum==3 
predict Y2 if spouse_LF_Y1==0 & RACE_sum==3 


reg  spouse_WAGE_YR1  AGE1 AGE1_sq AGE1_cub i.H1  [pw=Sample_Weight] if spouse_LF_Y1==1 & RACE_sum==2 
predict Y3 if spouse_LF_Y1==1 & RACE_sum==2 

reg  spouse_WAGE_YR1  AGE1 AGE1_sq AGE1_cub [pw=Sample_Weight] if spouse_LF_Y1==1 & RACE_sum==3 
predict Y4 if spouse_LF_Y1==1 & RACE_sum==3 




egen Y=rowmax(Y1 Y2 Y3 Y4)

	collapse Y, by(AGE1 H1  spouse_LF_Y1 RACE_sum)
	replace Y=0 if Y<0
	replace Y=(Y*1000) /5200 // convert to model units
	
	
	preserve 
	keep if RACE_sum==2
	drop RACE_sum
	sort AGE1  H1 spouse_LF_Y1 
	drop AGE1  H1 spouse_LF_Y1 

outsheet using "${data_model}\Blacks\Income_spouse1.txt", nolabel nonames replace	

restore 


keep if RACE_sum==3
	drop RACE_sum
	sort AGE1  H1 spouse_LF_Y1 
	drop AGE1  H1 spouse_LF_Y1 

outsheet using "${data_model}\Hispanics\Income_spouse1.txt", nolabel nonames replace	
}


*** SPOUSE'S MEDICAL COSTS
qui{
clear
use "${data}/MEPS_merged_Health_all_races.dta"
keep if AGE1<65 & AGE1>=25
keep if INSCOP_Y1==1 // this covers R1-R3 which we are using here.
keep if MAR1==1 & MAR2==1 // & MAR3==1
keep if educ_group==1

* HI = health insurance status 
gen spouse_HI = 1 if  spouse_PRIVAT1==1 // had her own offer and is insured
replace spouse_HI = 2 if spouse_PRIVAT1==0 & spouse_MCAID1==0 // not insured
replace spouse_HI = 3 if spouse_MCAID1==1 // not insured

label define ins6 1 "Has Private" 2 "Uninsured"  3 "Medicaid"
label values spouse_HI ins6

table RACE_sum, stat(fvpercent spouse_HI)
replace spouse_HI =2 if spouse_HI ==3 // medicaid or uninsured

drop if spouse_HI==.

gen spouse_charges_use = (spouse_TOTTCH_YR1 + spouse_RXEXP_YR1)*.6 
table RACE_sum spouse_HI, stat(mean spouse_TOTEXP_YR1 spouse_TOTTCH_YR1 spouse_charges_use spouse_TOTSLF_YR1)

drop if spouse_HI==.
	fillin AGE1 educ_group spouse_HI	
	replace AGE1_sq=AGE1^2 if _fillin==1
	
	
  reg spouse_TOTSLF_YR1 AGE1 AGE1_sq  if spouse_HI==1 & RACE_sum==2 // has PHI
predict OOP_wife1 if spouse_HI==1 & RACE_sum==2

  reg spouse_TOTSLF_YR1 AGE1 AGE1_sq  if spouse_HI==1 & RACE_sum==3 // has PHI
predict OOP_wife2 if spouse_HI==1 & RACE_sum==3 

  reg spouse_charges_use AGE1 AGE1_sq  if spouse_HI==2 & RACE_sum==2 // no PHI
predict OOP_wife3 if spouse_HI==2 & RACE_sum==2

  reg spouse_charges_use AGE1 AGE1_sq  if spouse_HI==2 & RACE_sum==3 // no PHI
predict OOP_wife4 if spouse_HI==2 & RACE_sum==3

gen OOP_wife=OOP_wife1 if spouse_HI==1 & RACE_sum==2
replace  OOP_wife=OOP_wife2 if spouse_HI==1 & RACE_sum==3
replace  OOP_wife=OOP_wife3 if spouse_HI==2 & RACE_sum==2
replace  OOP_wife=OOP_wife4 if spouse_HI==2 & RACE_sum==3

drop OOP_wife1 OOP_wife2 OOP_wife3 OOP_wife4

keep if RACE_sum==2 | RACE_sum==3
	
	collapse OOP_wife, by(AGE1 spouse_HI RACE_sum)
	sort RACE_sum  AGE1  spouse_HI

	
preserve 
	keep if RACE_sum==2
	sort AGE1 spouse_HI
	drop AGE1 spouse_HI RACE_sum
	replace OOP_wife=OOP_wife/5.2 
	outsheet using "${data_model}\Blacks\OOP_spouse.txt", nolabel nonames replace	
restore 

	keep if RACE_sum==3
	sort AGE1 spouse_HI
	drop AGE1 spouse_HI RACE_sum
	replace OOP_wife=OOP_wife/5.2 
outsheet using "${data_model}\Hispanics\OOP_spouse.txt", nolabel nonames replace
}

	

	
	
